SWEP.ViewModelFlip = false
SWEP.Category = "HL2 Beta Sweps";
SWEP.Author = "Valve";
SWEP.Contact = "n/a";
SWEP.Purpose = "Clean The Streets";
SWEP.Instructions = "Primary= Vaporize Secondary= Vaporize";
SWEP.PrintName = "Immolator";
SWEP.Slot = 5;
SWEP.SlotPos = 3;
SWEP.DrawCrosshair = true;
SWEP.DrawAmmo = false;
SWEP.ViewModel = "models/weapons/v_cremator.mdl";
SWEP.WorldModel = "models/weapons/w_immolator.mdl";
SWEP.ViewModelFOV = 70;
SWEP.ReloadSound = "0";
SWEP.HoldType = "shotgun";
SWEP.Spawnable = false;
SWEP.AdminSpawnable = true;
SWEP.Weight = 5;
SWEP.AutoSwitchTo = false;
SWEP.AutoSwitchFrom = true;
SWEP.FiresUnderwater = false;

SWEP.Primary.Zap = true;
SWEP.Primary.ZapRadius = 50;
SWEP.Primary.ZapDamage = 2000;
SWEP.Primary.Sound = "0"
SWEP.Primary.Tracer = 1;
SWEP.Primary.Automatic = true;
SWEP.Primary.Force = 1;
SWEP.Primary.FireFromHip = true;
SWEP.Primary.Ammo = "ar2";
SWEP.Primary.BreakAll = true;
SWEP.Primary.Ignite = true;
SWEP.Primary.ClipSize = 1000;
SWEP.Primary.DefaultClip = 3000;
SWEP.Primary.Recoil = 0.1;
SWEP.Primary.Damage = 12;
SWEP.Primary.NumberofShots = 1;
SWEP.Primary.Spread = 0;
SWEP.Primary.Delay = 0;
SWEP.Primary.TakeAmmo = 1;

SWEP.Secondary.Sound = "0"
SWEP.Secondary.Tracer = 1;
SWEP.Secondary.Force = 1;
SWEP.Secondary.FireFromHip = true;
SWEP.Secondary.BreakAll = true;
SWEP.Secondary.Zap = true;
SWEP.Secondary.ZapRadius = 50;
SWEP.Secondary.ZapDamage = 3000;
SWEP.Secondary.Ignite = true;
SWEP.Secondary.Recoil = 0.4;
SWEP.Secondary.Spread = 0.1;
SWEP.Secondary.Delay = 0.5;
SWEP.Secondary.Automatic = true;
SWEP.Secondary.TakeAmmo = 2;

function SWEP:Initialize()
    util.PrecacheSound(self.Primary.Sound);
    util.PrecacheSound(self.Secondary.Sound);
    if ( SERVER ) then
       self:SetWeaponHoldType( self.HoldType );
   end
end

function SWEP:PrimaryAttack()
   if ( !self:CanPrimaryAttack() ) then return end

//Default stuff, normally used in any condition.
   local tr = self.Owner:GetEyeTrace();
   self.Weapon:EmitSound ( self.Primary.Sound );
   self:ShootEffects();
   self.Weapon:SetNextPrimaryFire( CurTime() + self.Primary.Delay );
   self.Weapon:SetNextSecondaryFire( CurTime() + self.Primary.Delay );   self:TakePrimaryAmmo(self.Primary.TakeAmmo);
   local rnda = -self.Primary.Recoil;
   local rndb = self.Primary.Recoil * math.random(-1, 1);
   self.Owner:ViewPunch( Angle( rnda,rndb,rnda ) );

//The attack mode, can vary from the user settings
    if ( self.Primary.ModelShot ) then
    if (!SERVER) then return end;
    local ent = ents.Create ("prop_physics");
    ent:SetModel ( self.Primary.Model );
    if ( self.Primary.FireFromHip ) then
        ent:SetPos (self.Owner:EyePos() + (self.Owner:GetAimVector() * 32));
    else
        ent:SetPos (tr.HitPos + self.Owner:GetAimVector() * -16);
    end
    ent:SetAngles (self.Owner:EyeAngles());
    ent:Spawn();
    local phys = ent:GetPhysicsObject();
    local shot_length = tr.HitPos:Length();
    if ( self.Primary.Weld ) then
        local weld = constraint.Weld( tr.Entity, ent, tr.PhysicsBone, 0, 0 );
    end
    phys:ApplyForceCenter (self.Owner:GetAimVector():GetNormalized() * math.pow (shot_length, 3));
    cleanup.Add (self.Owner, "props", ent);
    undo.Create ("Thrown model");
    undo.AddEntity (ent);
    undo.SetPlayer (self.Owner);
    undo.Finish();

    if ( self.Primary.BreakAll ) then
        if( tr.Entity:IsValid() and tr.Entity:GetClass() == "prop_physics" ) then
            constraint.RemoveAll( tr.Entity );
            local physobject = tr.Entity:GetPhysicsObject();
            physobject:EnableMotion( true );
            physobject:SetVelocity( self.Owner:GetAimVector() * 2 );
        end

if ( self.Primary.Zap ) then
   local vaporize = ents.Create ( "point_hurt" )
   vaporize:SetKeyValue ( "DamageRadius", self.Primary.ZapRadius )
   vaporize:SetKeyValue ( "Damage" , self.Primary.ZapDamage )
   vaporize:SetKeyValue ( "DamageDelay", 0 )
   vaporize:SetKeyValue ( "DamageType" ,"67108864" )
   vaporize:SetPos ( tr.HitPos )
   vaporize:Fire ( "TurnOn" , "", 0 )
   vaporize:Fire ( "TurnOff" , "", 0.5 )
end

    if ( self.Primary.Ignite ) then
        if (!tr.Entity) then return false end
        if (!tr.Entity:IsValid() ) then return false end
        if (tr.Entity:IsPlayer()) then return false end
        if (tr.Entity:IsWorld()) then return false end
        if ( CLIENT ) then return true end
        local Time = math.random(20);
        tr.Entity:Extinguish();
        tr.Entity:Ignite( Time, 0 );
    end

self.Weapon:Stopsound("weapons/immolator/plasma+shoot.wav")

function SWEP:SecondaryAttack()
   if ( !self:CanPrimaryAttack() ) then return end

//Default stuff, normally used in any condition.
   local tr = self.Owner:GetEyeTrace();
   self.Weapon:EmitSound ( self.Secondary.Sound );
   self:ShootEffects();
   self.Weapon:SetNextPrimaryFire( CurTime() + self.Secondary.Delay );
   self.Weapon:SetNextSecondaryFire( CurTime() + self.Secondary.Delay );
   self:TakePrimaryAmmo(self.Secondary.TakeAmmo);
   local rnda = -self.Secondary.Recoil;
   local rndb = self.Secondary.Recoil * math.random(-1, 1);
   self.Owner:ViewPunch( Angle( rnda,rndb,rnda ) );

//The attack mode, can vary from the user settings
if ( self.Secondary.ModelShot ) then
    if (!SERVER) then return end
    local ent = ents.Create ("prop_physics");
    ent:SetModel ( self.Secondary.Model );
    if ( self.Secondary.FireFromHip ) then
        ent:SetPos (self.Owner:EyePos() + (self.Owner:GetAimVector() * 32));
    else
        ent:SetPos (tr.HitPos + self.Owner:GetAimVector() * -16);
    end
    ent:SetAngles (self.Owner:EyeAngles());
    ent:Spawn();
    local phys = ent:GetPhysicsObject();
    local shot_length = tr.HitPos:Length();
    if ( self.Secondary.Weld ) then
        local weld = constraint.Weld( tr.Entity, ent, tr.PhysicsBone, 0, 0 );
    end
    phys:ApplyForceCenter (self.Owner:GetAimVector():GetNormalized() * math.pow (shot_length, 3));
    cleanup.Add (self.Owner, "props", ent);
    undo.Create ("Thrown model");
    undo.AddEntity (ent);
    undo.SetPlayer (self.Owner);
    undo.Finish();
end

if ( self.Secondary.Zap ) then
   local vaporize = ents.Create ( "point_hurt" )
   vaporize:SetKeyValue ( "DamageRadius", self.Secondary.ZapRadius )
   vaporize:SetKeyValue ( "Damage" , self.Secondary.ZapDamage )
   vaporize:SetKeyValue ( "DamageDelay", 0 )
   vaporize:SetKeyValue ( "DamageType" ,"67108864" )
   vaporize:SetPos ( tr.HitPos )
   vaporize:Fire ( "TurnOn" , "", 0 )
   vaporize:Fire ( "TurnOff" , "", 0.5 )
end
end

   if ( self.Secondary.BreakAll ) then
       if( tr.Entity:IsValid() and tr.Entity:GetClass() == "prop_physics" ) then
           constraint.RemoveAll( tr.Entity );
           local physobject = tr.Entity:GetPhysicsObject();
           physobject:EnableMotion( true );
           physobject:SetVelocity( self.Owner:GetAimVector() * 2 );
       end

if ( self.Secondary.Ignite ) then
    if (!tr.Entity) then return false end
        if (!tr.Entity:IsValid() ) then return false end
        if (tr.Entity:IsPlayer()) then return false end
        if (tr.Entity:IsWorld()) then return false end
        if ( CLIENT ) then return true end
        local Time = math.random(20);
        tr.Entity:Extinguish();
        tr.Entity:Ignite( Time, 0 );
end


function SWEP:Reload()
   self.Weapon:DefaultReload(ACT_VM_RELOAD);
   return true
end

function SWEP:Deploy()
   self.Weapon:SendWeaponAnim(ACT_VM_DRAW);
   return true
end

function SWEP:Holster()
   return true
end